package com.bootdo.program.wallpaper.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.program.wallpaper.domain.BzClassificationDO;
import com.bootdo.program.wallpaper.service.BzClassificationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.program.wallpaper.domain.UserClassifyDO;
import com.bootdo.program.wallpaper.service.UserClassifyService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 用户自定义分类表
 * 
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2022-01-15 22:14:20
 */
 
@Controller
@RequestMapping("/wallpaper/userClassify")
public class UserClassifyController {
	@Autowired
	private UserClassifyService userClassifyService;
	
	@Autowired
	private BzClassificationService bzClassificationService;
	
	@GetMapping()
	@RequiresPermissions("wallpaper:userClassify:userClassify")
	String UserClassify(Model model){
		List<BzClassificationDO> list = bzClassificationService.list(null);
		model.addAttribute("cList",list);
		return "wallpaper/userClassify/userClassify";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wallpaper:userClassify:userClassify")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<UserClassifyDO> userClassifyList = userClassifyService.list(query);
		int total = userClassifyService.count(query);
		PageUtils pageUtils = new PageUtils(userClassifyList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wallpaper:userClassify:add")
	String add(){
	    return "wallpaper/userClassify/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wallpaper:userClassify:edit")
	String edit(@PathVariable("id") Long id,Model model){
		UserClassifyDO userClassify = userClassifyService.get(id);
		model.addAttribute("userClassify", userClassify);
	    return "wallpaper/userClassify/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wallpaper:userClassify:add")
	public R save( UserClassifyDO userClassify){
		if(userClassifyService.save(userClassify)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wallpaper:userClassify:edit")
	public R update( UserClassifyDO userClassify){
		userClassifyService.update(userClassify);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wallpaper:userClassify:remove")
	public R remove( Long id){
		if(userClassifyService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wallpaper:userClassify:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		userClassifyService.batchRemove(ids);
		return R.ok();
	}
	
}
